package com.example.week02.day1.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.week02.R;
import com.example.week02.day1.Constants.Constants;

//静态广播
public class SendBroadcast extends AppCompatActivity {

    Button broad1;
    EditText editText1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_send_broadcast);

        broad1 = findViewById(R.id.broad1);
        editText1 = findViewById(R.id.EditText1);

        broad1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击发送广播按钮后发送广播
                String content = editText1.getText().toString();
                Intent intent = new Intent();
                intent.setAction(Constants.ACTION_SEND_MSG);
                intent.putExtra(Constants.KEY_CONTENT,content);
                //android8以上要设置包名
                intent.setPackage("com.example.week02");
                //发送广播
                sendBroadcast(intent);
            }
        });
    }
}